export default {
  mounted(el, binding) {
    const placeholder = document.createElement('div')
    placeholder.style.width = el.offsetWidth + 'px'
    placeholder.style.height = el.offsetWidth + 'px'
    placeholder.style.backgroundColor = '#f5f5f5'
    el.style.display = 'none'
    el.onload = function () {
      placeholder.style.display = 'none'
      el.style.display = 'block'
    }
    el.onerror = function () {
      placeholder.innerHTML = '加载失败'
    }
    el.src = binding.value.src
  },
  unmounted(el) {
    const placeholder = el.previousElementSibling
    el.parentNode.removeChild(placeholder)
  }
}
